@echo off
rem chcp 65001
rem chcp 936
title   Git Working
rem mode con cols=100 lines=45

cls 

:initConfig
echo ###############        ###############  config start  ###############     ###############
for /f "delims=" %%a in ("%cd%") do (set "str2=%%~nxa")
rem save file
set myBatTempFile_folder=C:\Users\Public\Documents\%str2%_%~n0_folder.txt
set myBatTempFile_master_branch=C:\Users\Public\Documents\%str2%_%~n0_master_branch.txt
set myBatTempFile_development_branch=C:\Users\Public\Documents\%str2%_%~n0_development_branch.txt

rem default value
set defaultValue1=./
set defaultValue2=master
set defaultValue3=master

if exist "%myBatTempFile_folder%" (  
    for /f "delims=" %%b in (%myBatTempFile_folder%) do (set folder=%%b)
) else (set folder=%defaultValue1%)

if exist "%myBatTempFile_master_branch%" (  
    for /f "delims=" %%b in (%myBatTempFile_master_branch%) do (set master_branch=%%b)
) else (set master_branch=%defaultValue2%)

if exist "%myBatTempFile_development_branch%" (  
    for /f "delims=" %%b in (%myBatTempFile_development_branch%) do (set development_branch=%%b)
) else (set development_branch=%defaultValue3%)

cd %folder%

echo folder=%folder%
echo master_branch=%master_branch%
echo development_branch=%development_branch%

echo ###############        ###############  config   end  ###############     ###############




goto selectAll

:selectAll
echo ^^
echo [45m============================[0m
echo Select the corresponding operation:
echo     1/ status              6/ Merge            22/ exit
echo     2/ branch              7/ pull             33/ BBranch
echo     3/ checkout            8/ push             44/ stsah
echo     4/ add                 9/ log
echo     5/ commit              11/ config
if "%n%"=="" (set n=) else ( set n=)
set/p n=  [42m Please choice [0m:  
if "%n%"=="1" ( goto status)
if "%n%"=="2" ( goto branch )
if "%n%"=="3" ( goto checkout )
if "%n%"=="4" ( goto add) 
if "%n%"=="5" ( goto commit)
if "%n%"=="6" ( goto Merge)
if "%n%"=="7" ( goto pull)
if "%n%"=="8" ( goto push)
if "%n%"=="9" ( goto log)
if "%n%"=="11" ( goto config )
if "%n%"=="22" ( exit ) 
if "%n%"=="33" ( goto BBranch ) 
if "%n%"=="44" ( goto stsah ) 
goto other



:stsah
echo ^^
echo [45m######################################## [40;37m  git stsah  [45m #######################[0m
echo    1/ [36madd stash[0m     
echo    2/ [36mstsh list[0m     
echo    3/ [36mstash pop[0m     
echo    4/ [35mstash show[0m  
echo    5/ [35mstash clear[0m  
echo ^^
set stashKey=
set/p stashKey=  [42m Please choice [0m:  
if "%stashKey%"=="1" (goto stash_add)
if "%stashKey%"=="2" (goto stash_list)
if "%stashKey%"=="3" (goto stash_pop)
if "%stashKey%"=="4" (goto stash_show)
if "%stashKey%"=="5" (goto stash_clear)
goto selectAll

:stash_add
git stash 
echo ^^
echo stash Ok
goto stash_list

:stash_list
git stash list
echo ^^
echo list Ok
goto stsah

:stash_pop
git stash pop
echo ^^
echo pop Ok
goto stash_list

:stash_show
git stash show
echo ^^
echo show Ok
goto stsah

:stash_clear
git stash clear
echo ^^
echo clear Ok
goto stash_list



:config
echo ^^
rem echo ######################################## bat config  #######################
echo [45m######################################## [40;37m  bat config  [45m #######################[0m
echo    1/ [36mfolder[0m     
echo    2/ [36mmaster_branch[0m     
echo    3/ [36mdevelopment_branch[0m     
echo    4/ [35mDefault configuration[0m  
echo    5/ [32mBack or Click enter keys[0m  
echo ^^
set conmy=
set/p conmy=  [42m Please choice [0m:   
if "%conmy%"=="1" (goto set_folder)
if "%conmy%"=="2" (goto set_master_branch)
if "%conmy%"=="3" (goto set_development_branch)
if "%conmy%"=="4" (goto initConfigDefault)
goto showConfig

:initConfigDefault
rem delete sava file
if exist "%myBatTempFile_development_branch%" (del /s /q /f  "%myBatTempFile_development_branch%"    )
if exist "%myBatTempFile_master_branch%" (del /s /q /f  "%myBatTempFile_master_branch%"    )
if exist "%myBatTempFile_folder%" (del /s /q /f  "%myBatTempFile_folder%"    )
goto initConfig

:showConfig
echo ^^
echo folder = %folder%
echo master_branch = %master_branch%
echo development_branch = %development_branch%
goto selectAll

:set_development_branch
set inputValueB=
set/p inputValueB=  [42m Please input folder paths [0m:   
if "%inputValueB%"=="" (goto config) else (
    if exist "%myBatTempFile_development_branch%" (del /s /q /f  "%myBatTempFile_development_branch%"    )
    set development_branch=%inputValueB%
    echo %inputValueB%>>%myBatTempFile_development_branch%
    echo ^^
    echo change Ok
)
goto showConfig

:set_master_branch
set inputValueB=
set/p inputValueB=  [42m Please input folder paths [0m:   
if "%inputValueB%"=="" (goto config) else (
    if exist "%myBatTempFile_master_branch%" (del /s /q /f  "%myBatTempFile_master_branch%"    )
    set master_branch=%inputValueB%
    echo %inputValueB%>>%myBatTempFile_master_branch%
    echo ^^
    echo change Ok
)
goto showConfig

:set_folder
set inputValueF=
set/p inputValueF=  [42m Please input folder paths [0m:   
if "%inputValueF%"=="" (goto config) else (
    if exist "%myBatTempFile_folder%" (del /s /q /f  "%myBatTempFile_folder%"    )
    set folder=%inputValueF%
    echo %inputValueF%>>%myBatTempFile_folder%
    echo ^^
    echo change Ok
)
goto showConfig

:commit
echo ^^
rem echo ######################################## git commit -m 'commit information'  #######################
echo [45m######################################## [40;37m  git commit -m 'commit info'  [45m #######################[0m
echo [32mEnter to exit when null or Enter 1 to overwrite the last commit or Enter 2 close or Enter 3 show command[0m
set commitCon=git commit
goto commitEach

:commitEach
set m=
set/p  m=  commit info:  
echo ^^
if "%m%"=="" (
    if "%commitCon%"=="git commit" (
        echo Back 
    ) else (
        echo "%commitCon%"
        echo ^^
        %commitCon% 
    )
) else ( 
    if "%m%"=="3" ( 
        echo -- [36m%commitCon%[0m 
        echo ^^
        goto commitEach
    )
    if "%m%"=="2" ( 
        goto selectAll
    )
    if "%m%"=="1" ( 
        git commit --amend 
    ) else ( 
        set commitCon=%commitCon% -m "%m%"
        goto commitEach
    ) 
)
goto selectAll

:add
echo ^^
rem echo ######################################## git add  #######################
echo [45m######################################## [40;37m  git add  [45m #######################[0m
echo     1/ Add a file 
echo     2/ Add ll file 
echo     3/ Back        (Enter keys)
echo ^^
set/p  f=  [42mPlease choice file type to add[0m:  
echo ^^
if "%f%"=="1" ( goto one ) else ( if "%f%"=="2" ( goto all )  else (  goto selectAll ))
goto selectAll

:one
echo ^^
rem echo ######################################## git add 'file name'  #######################
echo [45m######################################## [40;37m  git add 'file name'  [45m #######################[0m
set/p  n=  [42mPlease input file name[0m:  
git add "%n%"
goto add

:all
echo ^^
rem echo ######################################## git add .  #######################
echo [45m######################################## [40;37m  git add .  [45m #######################[0m
echo Please wait ...
git add .
echo Ok
goto selectAll

:other
echo ^^
rem echo ######################################## other command   #######################
if "%n%"=="" (goto selectAll)
echo [45m######################################## [40;37m  other command  [45m #######################[0m
%n%
goto selectAll

:log
echo ^^
rem echo ######################################## git log   #######################
echo [45m######################################## [40;37m  git log  [45m #######################[0m
git log
goto selectAll

:push
echo ^^
rem echo ######################################## git push   #######################
echo [45m######################################## [40;37m  git push  [45m #######################[0m
echo ######### git branch
git branch
echo ^^
echo ######### git status
git status
echo ^^
echo ######### git push 
echo Please wait... 
git push 
echo Ok
goto selectAll

:pull
echo ^^
rem echo ######################################## git pull   #######################
echo [45m######################################## [40;37m  git pull  [45m #######################[0m
echo Please wait...
git pull
goto selectAll

:Merge
echo ^^
rem echo ######################################## git Merge  #######################
echo [45m######################################## [40;37m  git Merge  [45m #######################[0m
git branch
echo ^^
echo     1/ origin from branch '%master_branch%'  
echo     2/ origin from branch '%development_branch%'   
echo     3/ origin from branch other (or Back)
if "%oo%"=="" (set oo=) else (set oo=)
echo  ^^
set/p  oo=  [42mPlease choice origin[0m:  
echo ^^
if "%oo%"=="1" ( git merge %master_branch% ) else ( if "%oo%"=="2" ( git merge %development_branch% )  else (  git merge %oo% ))
goto selectAll

:checkout
echo ^^
rem echo ######################################## choice checkout branch  #######################
echo [45m######################################## [42;37m  git checkout branch  [45m #######################[0m
echo     1/ checkout to branch '%development_branch%'  
echo     2/ checkout to branch '%master_branch%'   
echo     3/ Transfer to branch other 
echo ^^
set  f=
set/p  f=  [42mPlease choice branch[0m:  
if "%f%"=="1" ( goto checkout_development_branch ) else ( if "%f%"=="2" ( goto checkout_master_branch)  else (goto checkout_xxx))
goto selectAll

:checkout_xxx
echo ^^
rem echo ######################################## git checkout %f%   #######################
echo [45m######################################## [42;37m  git checkout %f%  [45m #######################[0m
echo %f%
if "%f%"=="" ( goto selectAll ) else (git checkout %f%)
goto branch
goto selectAll

:checkout_master_branch
echo ^^
rem echo ######################################## git checkout %master_branch%   #######################
echo [45m######################################## [42;37m  git checkout %master_branch%  [45m #######################[0m
git checkout %master_branch%
goto branch
goto selectAll

:checkout_development_branch
echo ^^
rem echo ######################################## git checkout %development_branch%   #######################
echo [45m######################################## [42;37m  git checkout %development_branch%  [45m #######################[0m
git checkout %development_branch% 
goto branch
goto selectAll

:BBranch
echo ^^
rem echo ######################################## git branch  #######################
echo [45m######################################## [40;37m  git branch  [45m #######################[0m
echo    1/ [36mCreate new branch [0m   
echo    2/ [31mDelete branch[0m
echo    3/ [32mBack or Click enter keys[0m
echo ^^
set bb=
set/p  bb=  [42mPlease choice[0m: 
if "%bb%"=="1" (goto CreateBrach)
if "%bb%"=="2" (goto DeleteBrach)
goto selectAll

:DeleteBrach
echo ^^
git branch
echo ^^
set deleB=
set/p deleB= [31mPlease input the delete branch name: [0m
if "%deleB%"=="" (
    echo ^^
    git branch
    rem goto BBranch
) else (
    echo ^^
    git branch -d %deleB%
    echo ^^
    git branch
)
goto selectAll

:CreateBrach
echo ^^
git branch
echo ^^
set bnb=
set/p bnb= [36mPlease input the new branch name: [0m
if "%bnb%"=="" (
    echo ^^
    git branch
    rem goto BBranch
) else (
    echo ^^
    git checkout -b %bnb%
    echo ^^
    git branch
)
goto selectAll

:branch
echo ^^
rem echo ######################################## git branch  #######################
echo [45m######################################## [40;37m  git branch  [45m #######################[0m
git branch
goto selectAll


:status
echo ^^
echo [45m######################################## [40;37m  git status  [45m #######################[0m
git status
echo ^^
goto selectAll